<?php
/**
 * ============================================================================
 * Doxt Version: 1.0           
 * Web: http://www.doxt.com
 * Copyright (C) 2007 - 2010 Doxt Technology Inc., All Rights Reserved.
 * ---------------------------------------------
 * $Date: 2008.4.8
*/
  include_once("./config.php");
  $tpl = new PhplibTpl($conf["admin_tpl_path"]);
  if (! empty($_GET['mode']) )
  {   
    include($conf["include_path"] . $_GET['mode'] . ".php");
  }
  //分类列表文件
  include($conf["include_path"] . "list_cate.php");  
  $tpl -> set_file("main", "news.htm");
  $tpl -> set_block("main", "NEWS_LIST", "news_list");
  $tpl -> set_block("main","TYPE_LIST","type_list");
  $query = "SELECT * FROM $TBL_HOUSE WHERE hou_type=2 ";   //没有
  //用户按下了"查找"  
  $btn_sub = $_POST["btn_sub2"]; 
  if ($btn_sub)
  {
    $cate_id = $_POST["s_cate"];  //要显示的分类
	$featureday = $_POST["featureday"];  
	$feature = $_POST["feature"];  
	$saveplan = $_POST["saveplan"];  
	$recommended = $_POST["recommended"];  
	$del = $_POST["del"];  
	if ( !empty($cate_id) && $cate_id != 0 )
	{	  
	  $tmp_str = "";  //所有的子类
	  get_Pros_Sub($tmp_str, $cate_id);
	  $tmp_str = substr($tmp_str, 1, strlen($tmp_str));
	  if (! empty($tmp_str))
	  {
	    $query .= " and `cate_id` in (" . $cate_id . "," . $tmp_str . ")";
	  } 
	  else
	  {
	    $query .= " and `cate_id` in (" . $cate_id . ")";
	  }//End if
	} //End if
	$search_key = work_str( $_POST["search_key"] );  //查找关键字
	if (! empty($search_key))
	{
	   $search_str = " and (num like '%" . $search_key . "%') or (hou_name like '%" . $search_key . "%') or (address like '%" . $search_key . "%')";
      $query .= $search_str;
	} //End if
	if($featureday==1)
	{
		$search_str2 = " and featureday=1 ";
		$query .= $search_str2;
	}
	if($feature==1)
	{
		$search_str3 = " and feature=1 ";
		$query .= $search_str3;
	}
	if($saveplan==1)
	{
		$search_str4 = " and saveplan=1 ";
		$query .= $search_str4;
	}elseif($saveplan==2){
		$search_str4 = " and saveplan=2 ";
		$query .= $search_str4;

	}elseif($saveplan==3){
		$search_str4 = " and saveplan=3 ";
		$query .= $search_str4;
	}
	if($recommended==1)
	{
		$search_str5 = " and recommended=1 ";
		$query .= $search_str5;
	}
  } 
  $query = $query." and del like '%$del%' ";

  if($_GET['p']!=''&($_POST["btn_sub2"]==''||!isset($btn_sub)))
  {
	 $query=$_SESSION['S'];
  }else{
	 $_SESSION['S'] = $query;	
  }  

  //关闭数
  $querygb = $query." and del=1 ";
  $resultgb = mysql_query($querygb);
  $rowgb = @mysql_num_rows($resultgb);

   $_SESSION['URL'] = $_SERVER['QUERY_STRING'];

  $query_footer = " order by add_time desc";
  $query = $query . $query_footer;

  //实现分页
  include( $conf['base_path'] . "lib/make_pages.php");
  $cur_page = (int)$_GET["p"];   //获取当前页
  $url_param = preg_replace("/(p=[0-9]+)&/", "", $_SERVER['QUERY_STRING']);
  $pages = new Pager($query, $cur_page, 15, $url_param);
  $page_string = $pages -> getPageString();   
  $res = $pages -> getRsPerPage();
  while ($rows = @mysql_fetch_array($res))
  {
    $news_id = $rows["id"];	
	$queryq = "SELECT zh_cate_title,parent_id,cate_id FROM $TBL_HOU_CATE WHERE cate_id=".$rows['cate_id'];
	$resultq = mysql_query($queryq);
	$array = @mysql_fetch_array( $resultq );
	$file = '../../upload/house/'.$news_id."/".$rows['img'];
	$img = "<img src='$file' width='110'/><br>";
    
	if($rows['featureday']==1)
	{
		$featureday = "<font color='red'>是</font>";
	}else{
		$featureday = '否';
	}

	if($rows['del']==0)
	{
		$del = "<font color='red'>開</font>";
	}else{
		$del = '關';
	}

	if($rows['feature']==1)
	{
		$feature = "<font color='red'>是</font>";
	}else{
		$feature = '否';
	}

	if($rows['saveplan']!=0)
	{
		$saveplan = "<font color='red'>是</font>";
	}else{
		$saveplan = '否';
	}

	if($rows['recommended']==1)
	{
		$recommended = "<font color='red'>是</font>";
	}else{
		$recommended = '否';
	}
	$query1 = "SELECT zh_cate_title FROM $TBL_HOU_CATE WHERE cate_id=".$array['parent_id'];
	$result1 = mysql_query($query1);
	$array1 = @mysql_fetch_array( $result1 );	
    $edit_url = "?mode=edit_news&id=" . $news_id;
    $del_url = "?mode=del_news&del_id=". $news_id;
	$tpl -> set_var(array(
						"CATE_TITLE" => $array['zh_cate_title'],
						"parent_id"=>$array['parent_id'],
						"cate_id"=>$array['cate_id'],
						"NEWS_ID" => $news_id,
						"EDIT_URL" => $edit_url,
						"DEL_URL" => $del_url,
						"PAR_TITLE"=>$array1['zh_cate_title'],
						"name" => $rows["name"],
						"price" => $rows["price"],
						"user_id" => $rows["user_id"],
						"num" =>$rows["num"],
						"type" =>$rows["type"],

						"del" =>$del,
						"featureday" => $featureday,
						"feature" => $feature,
						"saveplan" => $saveplan,
						"recommended" => $recommended,
						"add_time" =>$rows["add_time"],	
							
						"img" => $img,
		                ));
	$tpl -> parse("news_list", "NEWS_LIST", true);
  } //End while
  if (empty($page_string))
  {
    $page_string = "此條件下暫時沒有租屋信息";
  }
  $page_string = $page_string.', 目前關閉筆數:'.$rowgb;
  $tpl -> set_var(array(
                        "SEARCH_KEY" => $search_key,
                        "SHOW_CATE" => $show_cate,
						"INIT_CATE" => $init_cate,
                        "PAGE_STRING" => $page_string
                      ));
  $tpl-> set_var( $conf);
  $tpl -> parse("Output", "main");
  $tpl -> p("Output");
  ?>